package com.punai.standard.controller;

import com.punai.common.annotation.Log;
import com.punai.common.core.controller.BaseController;
import com.punai.common.core.domain.AjaxResult;
import com.punai.common.core.page.TableDataInfo;
import com.punai.common.enums.BusinessType;
import com.punai.standard.domain.StaGxChapter;
import com.punai.standard.service.IStaGxChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 工序章节Controller
 * 
 * @author zxw
 * @date 2022-12-13
 */
@RestController
@RequestMapping("/sta/gxChapter")
public class StaGxChapterController extends BaseController
{
    @Autowired
    private IStaGxChapterService staGxChapterService;

    /**
     * 查询工序章节列表
     */
    @PreAuthorize("@ss.hasPermi('sta:gxChapter:list')")
    @GetMapping("/list")
    public TableDataInfo list(StaGxChapter staGxChapter)
    {
        startPage();
        List<StaGxChapter> list = staGxChapterService.selectStaGxChapterList(staGxChapter);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('sta:gxfee:list')")
    @GetMapping("/getSpecialtyList")
    public AjaxResult getSpecialtyList()
    {
        return AjaxResult.success(staGxChapterService.getSpecialtyList(getCompanyId()));
    }

    @PreAuthorize("@ss.hasPermi('sta:gxfee:list')")
    @GetMapping("/getVersionList/{specId}")
    public AjaxResult getVersionList(@PathVariable String specId)
    {
        return AjaxResult.success(staGxChapterService.getVersionListBySpecId(getCompanyId(),specId));
    }
    /**
     * 获取工序章节详细信息
     */
    @PreAuthorize("@ss.hasPermi('sta:gxChapter:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(staGxChapterService.selectStaGxChapterById(id));
    }

    /**
     * 新增工序章节
     */
    @PreAuthorize("@ss.hasPermi('sta:gxChapter:add')")
    @Log(title = "工序章节", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StaGxChapter staGxChapter)
    {
        return toAjax(staGxChapterService.insertStaGxChapter(staGxChapter));
    }

    /**
     * 修改工序章节
     */
    @PreAuthorize("@ss.hasPermi('sta:gxChapter:edit')")
    @Log(title = "工序章节", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StaGxChapter staGxChapter)
    {
        return toAjax(staGxChapterService.updateStaGxChapter(staGxChapter));
    }

    /**
     * 删除工序章节
     */
    @PreAuthorize("@ss.hasPermi('sta:gxChapter:remove')")
    @Log(title = "工序章节", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(staGxChapterService.deleteStaGxChapterByIds(ids));
    }
}
